﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Diagnostics;
using pryConvertTXT.EF;

namespace pryConvertTXT.Clases_DAO
{
    public class clsEmpresaRentaDAO
    {
        DataEntitiesSeguridad ContextoDeObjs = new DataEntitiesSeguridad();
        public bool Insertar(EmpresaRenta Obj)
        {
            try
            {
                ContextoDeObjs.AddToEmpresaRenta(Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.InnerException.Message, MsgBoxStyle.Critical);
                return false;
            }
            return true;
        }

        public bool Modificar(EmpresaRenta obj)
        {

            try
            {
                ContextoDeObjs.AttachTo("EmpresaRenta", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical);
                return false;

            }
            return true;
        }

        public bool Eliminar(EmpresaRenta obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("EmpresaRenta", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical);
                return false;
            }
            return true;
        }
        public List<EmpresaRenta> listar()
        {
            List<EmpresaRenta> lista = new List<EmpresaRenta>();
            var q = from c in ContextoDeObjs.EmpresaRenta
                    select c;

            lista = q.ToList();
            return lista;
        }
    }
}